package cn.ges.movie.config.database

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor
import org.mybatis.spring.annotation.MapperScan
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

/**
 * @author gespent@163.com  cn.ges.common.mapper
 * @date 2020/04/13 16:55
 */
@Configuration
@MapperScan(basePackages = ["com.ges.movie.mapper," +
        "com.ges.common.mapper," +
        "cn.ges.base.sta.mapper," +
        "cn.ges.movie.mapper," +
        "cn.ges.common.mapper"])
open class MybatisPlusConfig {

    private val log: Logger = LoggerFactory.getLogger(MybatisPlusConfig::class.java)

    /**
     * 分页插件
     */
    @Bean
    open fun paginationInterceptor(): PaginationInterceptor {
        return PaginationInterceptor()
    }

    /**
     * 性能分析拦截器,仅开发使用,
     */
    // @Bean
    open fun performanceInterceptor(): PerformanceInterceptor {
        val performanceInterceptor = PerformanceInterceptor()
        /*<!-- SQL 执行性能分析，开发环境使用，线上不推荐。 maxTime 指的是 sql 最大执行时长 -->*/
        performanceInterceptor.maxTime = 1000
        /*<!--SQL是否格式化 默认false-->*/
        performanceInterceptor.isFormat = true
        log.info("[dev] 加载SQL性能分析器")
        return performanceInterceptor
    }

}